<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="补货任务号" prop="planCode">
        <el-input
          v-model="queryParams.planCode"
          placeholder="请输入补货任务号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item label="创建日期" prop="createTime">
        <el-date-picker clearable size="small"
                        v-model="queryParams.startTime"
                        type="date"
                        value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>_
      <el-form-item label="" prop="createTime">
        <el-date-picker clearable size="small"
                        v-model="queryParams.endTime"
                        type="date"
                        value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
 <!--     <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:ccRukuInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:ccRukuInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:ccRukuInfo:remove']"
        >删除</el-button>
      </el-col>-->
<!--      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:ccRukuInfo:export']"
        >导出</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ccRukuInfoList" @selection-change="handleSelectionChange">
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="220">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-success"
            @click="handlePrint(scope.row)"
          >打印预览</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-order"
            @click="rkClickInfo(scope.row)"
          >查看详情</el-button>
        </template>
      </el-table-column>
     <!-- <el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column label="补货任务号" align="center" prop="planCode" width="150"/>
      <el-table-column label="待入库数量" align="center" prop="rkNumDd" width="150"/>
      <el-table-column label="入库数量" align="center" prop="rkNum" width="100"/>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.rk_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="单位" align="center" prop="unit" width="80">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.unit" :value="scope.row.unit"/>
        </template>
      </el-table-column>
      <el-table-column label="紧急程度" align="center" prop="res2" width="100"/>
      <el-table-column label="打印状态" align="center" prop="res1" width="100"/>
      <el-table-column label="打印次数" align="center" prop="sn" width="100"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createUser" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:ccRukuInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:ccRukuInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改入库任务对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="入库任务号" prop="planCode">
          <el-input v-model="form.planCode" placeholder="请输入入库任务号" />
        </el-form-item>
        <el-form-item label="物料号" prop="itemCode">
          <el-input v-model="form.itemCode" placeholder="请输入物料号" />
        </el-form-item>
        <el-form-item label="物料名称" prop="itemName">
          <el-input v-model="form.itemName" placeholder="请输入物料名称" />
        </el-form-item>
        <el-form-item label="待入库数量" prop="rkNumDd">
          <el-input v-model="form.rkNumDd" placeholder="请输入待入库数量" />
        </el-form-item>
        <el-form-item label="入库数量" prop="rkNum">
          <el-input v-model="form.rkNum" placeholder="请输入入库数量" />
        </el-form-item>
        <el-form-item label="供应商编号" prop="suppCode">
          <el-input v-model="form.suppCode" placeholder="请输入供应商编号" />
        </el-form-item>
        <el-form-item label="供应商名称" prop="suppName">
          <el-input v-model="form.suppName" placeholder="请输入供应商名称" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择状态">
            <el-option
              v-for="dict in dict.type.rk_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="规格型号" prop="spec">
          <el-input v-model="form.spec" placeholder="请输入规格型号" />
        </el-form-item>
        <el-form-item label="单位" prop="unit">
          <el-select v-model="form.unit" placeholder="请选择单位">
            <el-option
              v-for="dict in dict.type.unit"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="库位编号" prop="kwCode">
          <el-input v-model="form.kwCode" placeholder="请输入库位编号" />
        </el-form-item>
        <el-form-item label="库位名称" prop="kwName">
          <el-input v-model="form.kwName" placeholder="请输入库位名称" />
        </el-form-item>
        <el-form-item label="标签号" prop="lableCode">
          <el-input v-model="form.lableCode" placeholder="请输入标签号" />
        </el-form-item>
        <el-form-item label="器具位置号" prop="applianceyCode">
          <el-input v-model="form.applianceyCode" placeholder="请输入器具位置号" />
        </el-form-item>
        <el-form-item label="器具名称" prop="applianceyName">
          <el-input v-model="form.applianceyName" placeholder="请输入器具名称" />
        </el-form-item>
        <el-form-item label="sps区" prop="spsArea">
          <el-input v-model="form.spsArea" placeholder="请输入sps区" />
        </el-form-item>
        <el-form-item label="备注" prop="bz">
          <el-input v-model="form.bz" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="创建人" prop="createUser">
          <el-input v-model="form.createUser" placeholder="请输入创建人" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--  详情弹窗 -->
    <el-dialog :title="title" :visible.sync="openInfo"  width="1500px" append-to-body fullscreen="true">
      <div id="indexInfo">
        <!-- 注册名 -->
        <indexInfo ref="indexInfo"></indexInfo>
      </div>
    </el-dialog>


    <!-- 打印窗口 -->
    <el-dialog :title="title" :visible.sync="openpr" width="850px" append-to-body custom-class="zhazhachao">
      <ContractInfo :formObj="priList"   @changeCancel="changeCancel"></ContractInfo>
    </el-dialog>


  </div>
</template>

<script>
import { listCcRukuInfo,listCcRukuInfoGroup, getCcRukuInfo, delCcRukuInfo, addCcRukuInfo, updateCcRukuInfo } from "@/api/business/ccRukuInfo";
import indexInfo from './indexInfo.vue';
import ContractInfo from './contractSingle.vue';
export default {
  name: "CcRukuInfo",
  dicts: ['rk_status', 'unit'],
  components: {
    indexInfo,ContractInfo
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 入库任务表格数据
      ccRukuInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openInfo:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        planCode: null,
        itemCode: null,
        itemName: null,
        rkNumDd: null,
        rkNum: null,
        suppCode: null,
        suppName: null,
        status: null,
        spec: null,
        unit: null,
        kwCode: null,
        kwName: null,
        lableCode: null,
        applianceyCode: null,
        applianceyName: null,
        spsArea: null,
        bz: null,
        createUser: null,
        startTime: null,
        endTime:null
      },
      // 表单参数
      form: {},
      //打印的数据集合
      priList:[],
      openpr:false,
      queryParamsId:{
        pageNum: 1,
        pageSize: 800,
        planCode:null,
      },

      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {

    //查看补货任务详情
    rkClickInfo(row, column, event){
      this.reset();
      this.openInfo = true;
      this.title = "补货任务详情";
      setTimeout(() => {
        this.$refs.indexInfo.getListInfo(row.planCode);
      }, 8);
    },


    /** 查询入库任务列表 */
    getList() {
      this.loading = true;
      listCcRukuInfoGroup(this.queryParams).then(response => {
        this.ccRukuInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        planCode: null,
        itemCode: null,
        itemName: null,
        rkNumDd: null,
        rkNum: null,
        suppCode: null,
        suppName: null,
        status: null,
        spec: null,
        unit: null,
        kwCode: null,
        kwName: null,
        lableCode: null,
        applianceyCode: null,
        applianceyName: null,
        spsArea: null,
        bz: null,
        createTime: null,
        createUser: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加入库任务";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCcRukuInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改入库任务";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCcRukuInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCcRukuInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },


    /** 打印按钮操作 */
    handlePrint(row) {
      const planCode = row.planCode;
      this.queryParamsId.planCode=planCode;
      listCcRukuInfo(this.queryParamsId).then(response => {
        this.priList = response.rows;
        this.openpr = true;
        this.title = "皮卡SPS+PTL补货单";
      });
    },

    changeCancel(data){
      this.openpr = data;
      this.getList();
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除入库任务编号为"' + ids + '"的数据项？').then(function() {
        return delCcRukuInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/ccRukuInfo/export', {
        ...this.queryParams
      }, `ccRukuInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>
  /deep/.zhazhachao .el-dialog__body,/deep/.zhazhachao .app-container{
    padding-top: 0px !important;
  }

</style>

